package com.elinkway.infinitemovies.async;

import android.content.Context;

import com.elinkway.infinitemovies.bean.CloudErrorBean;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.CloudErrorParser;
import com.lvideo.http.bean.LVideoDataHull;

/**
 * Created by zhaopeipei on 2016/3/30.
 */
public class RequestCloudErrorTask extends MoviesHttpAsyncTask <CloudErrorBean>{

    String mUrl;

    RequestResultListener<CloudErrorBean> mListener;

    public void setListener(RequestResultListener<CloudErrorBean> listener) {
        this.mListener = listener;
    }

    public RequestCloudErrorTask(Context context, String url)
    {
        super(context);
        mUrl = url;
    }

    @Override
    public LVideoDataHull<CloudErrorBean> doInBackground() {
        return MoviesHttpApi.requestCloudError(new CloudErrorParser(), mUrl);
    }

    @Override
    public void onPostExecute(int updateId, CloudErrorBean result) {
        if (mListener != null) {
            mListener.onRequestSuccess(updateId, result);
        }

    }

    @Override
    public void netNull() {
        if (mListener != null) {
            mListener.onRequestFailed();
        }
        super.netNull();
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        if (mListener != null) {
            mListener.onRequestFailed();
        }
        super.netErr(updateId, errMsg);
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        if (mListener != null) {
            mListener.onRequestFailed();
        }
        super.dataNull(updateId, errMsg);
    }
}
